﻿

using Edge.Repository.Model;
using Edge.Repository.Model.CameraSys;
using Edge.Repository.Model.EMS;
using Edge.Repository.Model.ResistanceWelding;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Edge.Repository.Base
{
    public class EdgeSqlSugarClient
    {
        /// <summary>
        ///  初始化数据库
        ///  “System.Data.SQLite, Version=1.0.102.0, C
        /// </summary>
        public static void SqlSugarClient()
        {
            //Create db
            Console.WriteLine("#### SqlSugarClient Start ####");
            string conn = EdgeConfig.ConnectionString;
            SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
            {
                DbType = DbType.Sqlite,

                ConnectionString = conn,
                InitKeyType = InitKeyType.Attribute,
                IsAutoCloseConnection = true,
                AopEvents = new AopEvents
                {
                    OnLogExecuting = (sql, p) =>
                    {
                        Console.WriteLine(sql);
                        Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
                    }
                }
            });

            //If no exist create datebase 
            db.DbMaintenance.CreateDatabase();

            //Use db query
            //var dt = db.Ado.GetDataTable("select 1");

            //Create tables
            db.CodeFirst.InitTables(


            #region base 

              typeof(CS_KeyVal)
                // 用户员工  
                , typeof(CS_User)
            #endregion

            #region 业务

                  // 配置类型 
                  //  typeof(RW_Equipment)
                  //, typeof(RW_JcqConfig)
                  //, typeof(RW_ErrorRecord)
                  //, typeof(RW_ShangBao)

                  , typeof(EmsEquipModel)
                  , typeof(EmsAlarmModel)



            #endregion

          , typeof(CameraConfigModel) 
          , typeof(CameraDataModel)
           

                );

            //var id = db.Insertable(new Order() { Name = "order1", CustomId = 1, Price = 0, CreateTime = DateTime.Now }).ExecuteReturnIdentity();

            ////Insert data
            //db.Insertable(new OrderItem() { OrderId = id, Price = 0, CreateTime = DateTime.Now }).ExecuteCommand();
            //Console.WriteLine("#### SqlSugarClient End ####");

        }


    }

}
